﻿using GISforTT_API;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ESRI.ArcGIS.Client;
using System.Collections.Generic;
using System.Windows.Input;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Media;
using ESRI.ArcGIS.Client.Geometry;

namespace GISforTT_Test
{
    
    
    /// <summary>
    ///This is a test class for ArcGisMapTest and is intended
    ///to contain all ArcGisMapTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ArcGisMapTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ArcGisMap Constructor
        ///</summary>
        [TestMethod()]
        public void ArcGisMapConstructorTest()
        {
            ArcGisMap target = new ArcGisMap();

            // Would this do?
            Assert.IsNotNull(target.Map.Layers);
            Assert.IsTrue(target.isDrawObjectCreated());
        }

       
        /// <summary>
        ///A test for AddBookmarkPin
        ///</summary>
        [TestMethod()]
        public void AddBookmarkPinTest()
        {
            ArcGisMap target = new ArcGisMap();
            BookmarkPin pin = new BookmarkPin(new Point(100, 50));
            GraphicsLayer graphicsLayer = target.Map.Layers["BookmarksLayer"] as GraphicsLayer;
            int initialCount = graphicsLayer.Graphics.Count;
            target.AddBookmarkPin(pin);
            int finalCount = graphicsLayer.Graphics.Count;

            Assert.AreEqual(initialCount + 1, finalCount);
        }

        /// <summary>
        ///A test for ClearGraphics
        ///</summary>
        [TestMethod()]
        public void ClearGraphicsTest()
        {
            ArcGisMap target = new ArcGisMap();
            target.ClearGraphics();
            GraphicsLayer graphicsLayer = target.Map.Layers["AnnotationsLayer"] as GraphicsLayer;
            
            int finalCount = graphicsLayer.Graphics.Count;
            Assert.AreEqual(finalCount, 0);            
        }

        /// <summary>
        ///A test for CreateBookmarkPins
        ///</summary>
        [TestMethod()]
        public void CreateBookmarkPinsTest()
        {
            ArcGisMap target = new ArcGisMap();
            List<Bookmark> bmrks = new List<Bookmark>();
            GraphicsLayer graphicsLayer = target.Map.Layers["BookmarksLayer"] as GraphicsLayer;
            int initialCount = graphicsLayer.Graphics.Count;

            bmrks.Add(new Bookmark(-114.165225251302, 51.0199795790397, -114.149512923988, 51.0355755135701, "Out of order lights", "0006780", Bookmark.BookmarkPriority.High));
            bmrks.Add(new Bookmark(-114.146822616181, 51.1247138317455, -114.12585847052, 51.1364297207226, "Repair Transformer", "0006889", Bookmark.BookmarkPriority.Medium));

            target.CreateBookmarkPins(bmrks);

            int finalCount = graphicsLayer.Graphics.Count;
            Assert.AreEqual(initialCount + 2, finalCount);
        }



        /// <summary>
        ///A test for InitializeMapLayers
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GISforTT_API.dll")]
        public void InitializeMapLayersTest()
        {
            ArcGisMap_Accessor target = new ArcGisMap_Accessor();
            int layersCountBefore = target.Map.Layers.Count;
            target.InitializeMapLayers();
            int layersCountAfter = target.Map.Layers.Count;

            Assert.AreEqual(layersCountBefore + MapLayersManager.Instance.MapLayers.Count, layersCountAfter);

        }

        
        /// <summary>
        ///A test for PanTo
        ///</summary>
        [TestMethod()]
        public void PanToTest()
        {
            ArcGisMap target = new ArcGisMap();
            Point screenPoint = new Point(100, 20);
            target.PanTo(screenPoint);
            
            // Will this work? Theoretically the map should have this point as the center
            // TODO: figure out how to test this from the extent of the map
        }

        /// <summary>
        ///A test for RemoveMapLayer
        ///</summary>
        [TestMethod()]
        public void RemoveMapLayerTest()
        {
            ArcGisMap_Accessor target = new ArcGisMap_Accessor();

            int layersInitialCount = target.Map.Layers.Count;
            
            ArcGISTiledMapServiceLayer tiledServiceLayer = new ArcGISTiledMapServiceLayer();
            tiledServiceLayer.ID = "Imagery";
            target.RemoveMapLayer(tiledServiceLayer);

            int layersFinalCount = target.Map.Layers.Count;

            Assert.AreEqual(layersInitialCount, layersFinalCount + 1);
            
        }

        /// <summary>
        ///A test for SetDrawFreehandMode
        ///</summary>
        [TestMethod()]
        public void SetDrawFreehandModeTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            target.SetDrawFreehandMode();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for SetDrawPointMode
        ///</summary>
        [TestMethod()]
        public void SetDrawPointModeTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            target.SetDrawPointMode();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for SetDrawPolygonMode
        ///</summary>
        [TestMethod()]
        public void SetDrawPolygonModeTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            target.SetDrawPolygonMode();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for SetDrawPolylineMode
        ///</summary>
        [TestMethod()]
        public void SetDrawPolylineModeTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            target.SetDrawPolylineMode();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for SetDrawRectangleMode
        ///</summary>
        [TestMethod()]
        public void SetDrawRectangleModeTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            target.SetDrawRectangleMode();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for StopDrawing
        ///</summary>
        [TestMethod()]
        public void StopDrawingTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            target.StopDrawing();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        
        /// <summary>
        ///A test for Zoom
        ///</summary>
        [TestMethod()]
        public void ZoomTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            double factor = 0F; // TODO: Initialize to an appropriate value
            target.Zoom(factor);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for ZoomTo
        ///</summary>
        [TestMethod()]
        public void ZoomToTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            //Geometry geom = null; // TODO: Initialize to an appropriate value
            //target.ZoomTo(geom);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for graphic_MouseLeftButtonDown
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GISforTT_API.dll")]
        public void graphic_MouseLeftButtonDownTest()
        {
            ArcGisMap_Accessor target = new ArcGisMap_Accessor(); // TODO: Initialize to an appropriate value
            object sender = null; // TODO: Initialize to an appropriate value
            MouseButtonEventArgs e = null; // TODO: Initialize to an appropriate value
            target.graphic_MouseLeftButtonDown(sender, e);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        
        /// <summary>
        ///A test for InitializeGraphics
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GISforTT_API.dll")]
        public void InitializeGraphicsTest()
        {
            ArcGisMap_Accessor target = new ArcGisMap_Accessor();
            target.InitializeGraphics();
            Assert.IsTrue(target.isDrawObjectCreated());            
        }

        /// <summary>
        ///A test for setIsABackgroundMap
        ///</summary>
        [TestMethod()]
        public void setIsBackgroundMapTest()
        {
            ArcGisMap target = new ArcGisMap();
            bool isBg = false;
            target.setIsABackgroundMap(isBg);
            Assert.AreEqual(target.isABackgroundMap(), isBg);
        }

        /// <summary>
        ///A test for isLayersListVisible
        ///</summary>
        [TestMethod()]
        public void isLayersListVisibleTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.isLayersListVisible();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for isMapInDrawMode
        ///</summary>
        [TestMethod()]
        public void isMapInDrawModeTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.isMapInDrawMode();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for setExtentFromEnvelop
        ///</summary>
        [TestMethod()]
        public void setExtentFromEnvelopTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            Envelope input = null; // TODO: Initialize to an appropriate value
            target.setExtentFromEnvelop(input);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for setExtentFromLtdLng
        ///</summary>
        [TestMethod()]
        public void setExtentFromLtdLngTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            double lat = 0F; // TODO: Initialize to an appropriate value
            double lng = 0F; // TODO: Initialize to an appropriate value
            target.setExtentFromLtdLng(lat, lng);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for setLinkedGhostFrame
        ///</summary>
        [TestMethod()]
        public void setLinkedGhostFrameTest()
        {
            ArcGisMap target = new ArcGisMap();
            GhostFrame gf = new GhostFrame(BackgroundMapLayer.Instance.getBackgroundMap(), target.Extent, new SolidColorBrush(Colors.Red));
            target.LinkedGhostFrame = gf;

            Assert.AreEqual(gf, target.LinkedGhostFrame);
        }

        /// <summary>
        ///A test for CanPan
        ///</summary>
        [TestMethod()]
        public void CanPanTest()
        {
            ArcGisMap target = new ArcGisMap();
            bool expected = false;
            bool actual;
            target.CanPan = expected;
            actual = target.CanPan;
            Assert.AreEqual(expected, actual);            
        }

        /// <summary>
        ///A test for CanZoom
        ///</summary>
        [TestMethod()]
        public void CanZoomTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            target.CanZoom = expected;
            actual = target.CanZoom;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Center
        ///</summary>
        [TestMethod()]
        public void CenterTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            Point actual;
            actual = target.Center;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Extent
        ///</summary>
        [TestMethod()]
        public void ExtentTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            Envelope actual;
            actual = target.Extent;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for InitialExtent
        ///</summary>
        [TestMethod()]
        public void InitialExtentTest()
        {
            ArcGisMap target = new ArcGisMap();
            Envelope expected = target.Map.Extent;
            Envelope actual;
            // setting should have been done in the constructor
            actual = target.InitialExtent;
            Assert.AreEqual(expected, actual);            
        }

        /// <summary>
        ///A test for Map
        ///</summary>
        [TestMethod()]
        public void MapTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            Map expected = null; // TODO: Initialize to an appropriate value
            Map actual;
            target.Map = expected;
            actual = target.Map;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for MapHeight
        ///</summary>
        [TestMethod()]
        public void MapHeightTest()
        {
            ArcGisMap target = new ArcGisMap();
            double expected = 0F;
            double actual;
            target.MapHeight = expected;
            actual = target.MapHeight;
            Assert.AreEqual(expected, actual);            
        }

        /// <summary>
        ///A test for MapURL
        ///</summary>
        [TestMethod()]
        public void MapURLTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            string actual;
            actual = target.MapURL;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for MapWidth
        ///</summary>
        [TestMethod()]
        public void MapWidthTest()
        {
            ArcGisMap target = new ArcGisMap();
            double expected = 0F;
            double actual;
            target.MapWidth = expected;
            actual = target.MapWidth;
            Assert.AreEqual(expected, actual);            
        }

        /// <summary>
        ///A test for ShowLayersList
        ///</summary>
        [TestMethod()]
        public void ShowLayersListTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            target.ShowLayersList = expected;
            actual = target.ShowLayersList;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ZoomFactor
        ///</summary>
        [TestMethod()]
        public void ZoomFactorTest()
        {
            ArcGisMap target = new ArcGisMap(); // TODO: Initialize to an appropriate value
            double actual;
            actual = target.ZoomFactor;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
    }
}
